<?php
class url {
	private $urlControll = '';
	private $urlFunction = '';
	private $par = array();
	public $instance = null;
	private $url;
	static $webaddress = '';
	
	public function getUrl_get(){
		$this->urlControll = $urlControll = (isset($_GET['skyc']) && !empty($_GET['skyc'])) ? urlencode($_GET['skyc']) : 'index';
		$this->urlFunction = $urlFunction = (isset($_GET['skyf']) && !empty($_GET['skyf'])) ? urlencode($_GET['skyf']) : 'welcome';
		$this->par = (isset($_GET['par']) && !empty($_GET['par'])) ? urlencode($_GET['par']) : '';

		$controlPath = ROOT.'./application/controllers/'.$urlControll.'_control.php';
		
		if(isset($this->par) && $this->par){
			$params = explode('.',$this->par);
			$pad_array = array();
			if(count($params)>1){
			for($i=0;$i<count($params)-1;$i++){ $pad_array[] = $params[$i]; }
			}
			$this->par = $pad_array;
		}
		if(file_exists($controlPath)) {
			require_once $controlPath;
			if(!is_object($this->instance)) $this->instance =  new $urlControll();
			if(isset($this->par) && $this->par){
		 	$this->instance->$urlFunction($this->par);
		    } else $this->instance -> $urlFunction();
		}
	}
	
	function getUrl_pathinfo(){
		self::$webaddress = ($https && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] == 80 ? '' : ":{$_SERVER['SERVER_PORT']}");
		$url_s = (isset($_SERVER['PATH_INFO']) && !is_null($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : getenv('PATH_INFO');		
		if(isset($url_s) && $url_s){
			$url_array = explode('/',substr($url_s,1,strlen($url_s)-1));
			$urlControll = (count($url_array) >= 1) ? $url_array[0] : 'index';
			$urlFunction = (count($url_array) >= 2) ? $url_array[1] : 'welcome';
			
			if(strpos($urlFunction,'.') !== false){
			$urlFunction = current(explode('.',$urlFunction));
			}
			if(count($url_array)>2){
				for($i=3;$i<=count($url_array);$i++){
				 if(strrpos($url_array[$i-1],'.') !== false) {
				 $url_explode = current(explode('.',$url_array[$i-1]));
				 $urlParams[] = $url_explode;
				}else $urlParams[] = $url_array[$i-1];
			}
		}
		} else {$urlControll = 'index'; $urlFunction = 'welcome';}
		$controlPath = ROOT.'./application/controllers/'.$urlControll.'_control.php';

		if(file_exists($controlPath)) {
			require_once $controlPath;			
			if(method_exists($urlControll,$urlFunction)){
			if(!is_object($this->instance)) $this->instance = new $urlControll();
			if(isset($urlParams) && $urlParams) return $this->instance->$urlFunction($urlParams);
			else return $this->instance->$urlFunction();
			} else Controller::message('lose','error','welcome');
		}
		
	}
}
?>
